// run: time $exec < input
#include <iostream>
#include <queue>
#include <string>

namespace tue
{
	namespace detail
	{
		int const alphabet_size = 26;
		int const max_size = 400000;

		int next[max_size][alphabet_size];
		int fail[max_size];
		int word_tail_count[max_size];

		struct trie
		{
			trie() { reset(); }

			void reset()
			{
				current_free = 0;
				root = allocate();
			}

			void insert(std::string const & s)
			{
				int now = root;

				int len = s.size();
				for (int i = 0; i < len; now = next[now][s[i++] - 'a'])
					if (next[now][s[i] - 'a'] == -1)
						next[now][s[i] - 'a'] = allocate();
				word_tail_count[now]++;
			}

			void make_ac_automaton()
			{
				std::queue<int> q;
				fail[root] = root;
				for (int ch = 0; ch < alphabet_size; ch++)
					if (next[root][ch] == -1)
						next[root][ch] = root;
					else {
						fail[next[root][ch]] = root;
						q.push(next[root][ch]);
					}

				while (!q.empty()) {
					int now = q.front(); q.pop();
					for (int ch = 0; ch < alphabet_size; ch++)
						if (next[now][ch] == -1)
							next[now][ch] = next[fail[now]][ch];
						else {
							fail[next[now][ch]] = next[fail[now]][ch];
							q.push(next[now][ch]);
						}
				}
			}

			int match(std::string const & s)
			{
				int now = root;
				int count = 0;
				int len = s.size();
				for (int i = 0; i < len; i++) {
					now = next[now][s[i] - 'a'];
					for (int tmp = now; tmp != root; tmp = fail[tmp]) {
						count += word_tail_count[tmp];
						word_tail_count[tmp] = 0;
					}
				}
				return count;
			}

		private:

			int allocate()
			{
				for (int i = 0; i < alphabet_size; i++)
					next[current_free][i] = -1;
				word_tail_count[current_free] = 0;
				return current_free++;
			}

			int current_free;
			int root;
		};
	}

	using detail::trie;
}

int n;
std::string s;

int main()
{
	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	tue::trie aca;
	while (T--) {
		std::cin >> n;
		aca.reset();
		for (int i = 0; i < n; i++) {
			std::cin >> s;
			aca.insert(s);
		}
		aca.make_ac_automaton();
		std::cin >> s;
		std::printf("%d\n", aca.match(s));
	}
}

